package com.cn.customer.housekeeping.housekeepingb.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.cn.customer.housekeeping.housekeepingb.R;

import java.util.ArrayList;
import java.util.List;



public class MerchandiseListAdapter extends RecyclerView.Adapter< MerchandiseListAdapter.NewsListHolder>{
    public Context mContext;

    private onItemClickListener mOnItemClickListener;
private List<String> list=new ArrayList<>();;
    public MerchandiseListAdapter(Activity baseActivity,List list) {
        super();
        mContext = baseActivity;
        this.list=list;

    }


    public List<String> getData() {
        return list;
    }


    @Override
    public NewsListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new NewsListHolder(LayoutInflater.from(mContext).inflate(R.layout.item_merchandise, parent, false));
    }



    @Override
    public void onBindViewHolder(final NewsListHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class NewsListHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {



        public NewsListHolder(View itemView) {
            super(itemView);
//            ButterKnife.bind(this, itemView);
//            itemView.setOnClickListener(this);
//            itemView.setOnLongClickListener(this);
//            tvMerchandiseButton.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (mButtonClickListener != null)
//                        mButtonClickListener.onClick(getAdapterPosition(), getDataList().get(getAdapterPosition()));
//                }
//            });
        }

        @Override
        public void onClick(View v) {
            if (mOnItemClickListener != null) {
//                mOnItemClickListener.onItemClick(v, getAdapterPosition(), getDataList().get(getAdapterPosition()));
            } else
                Toast.makeText(mContext, "item click pos:" + getAdapterPosition(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public boolean onLongClick(View v) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemLongClick(NewsListHolder.this, v, getAdapterPosition());
            } else
                Toast.makeText(mContext, "item long click pos:" + getAdapterPosition(), Toast.LENGTH_SHORT).show();
            return false;
        }
    }

    /**
     * 自定义的recyclerView点击监听
     */
    public interface onItemClickListener {
//        void onItemClick(View v, int position, MerchandiseBean data);

        void onItemLongClick(RecyclerView.ViewHolder viewHolder, View v, int position);
    }

    /**
     * 每个订单按钮的点击监听
     */
//    public interface ButtonClickListener {
//        void onClick(int position, MerchandiseBean data);
//    }


}
